package com.wc5818.chuShen.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.chuShen.entity.FirstAuditReport;
import com.wc5818.chuShen.mapper.FirstAuditReportMapper;
import com.wc5818.common.AjaxResult;
import com.wc5818.wcComOrder.entity.WcComOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-21
 */
@RestController
@RequestMapping("/chuShen")
public class FirstAuditReportController {
    @Autowired
    FirstAuditReportMapper firstAuditReportMapper;

    @GetMapping("/search")
    public Object search(Integer baseInfoId, String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        FirstAuditReport firstAuditReport = new FirstAuditReport();
        firstAuditReport.setBaseInfoId(baseInfoId);
        firstAuditReport.setCreateTime(LocalDateTime.now());
        firstAuditReport.setOrderNum(orderNum);

        // 需要对接第三方风控平台接口
        firstAuditReport.setScore(999);

        if(firstAuditReportMapper.insert(firstAuditReport) > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(firstAuditReport.getScore());
        }

        return ajaxResult;
    }

    @GetMapping("/queryByOrderNum")
    public Object queryByOrderNum(String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = firstAuditReportMapper.selectList(new QueryWrapper<FirstAuditReport>().eq("orderNum", orderNum));
        if(list != null && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));
        }

        return ajaxResult;
    }
}
